package com.woniuxy.oa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.woniuxy.oa.entity.GoodsRepository;
import com.woniuxy.oa.entity.Goods_claim;
import com.woniuxy.oa.entity.PageBean;
import com.woniuxy.oa.mapper.Approval_goodsclaimMapper;
import com.woniuxy.oa.mapper.EmployeeMapper;
import com.woniuxy.oa.mapper.GoodsRepositoryMapper;
import com.woniuxy.oa.mapper.Goods_claimMapper;
import com.woniuxy.oa.service.Goods_claimService;
@Service
public class Goods_claimServiceImpl implements Goods_claimService{
	
	@Autowired
	Goods_claimMapper goods_claimMapper;
	

	
	@Autowired
	EmployeeMapper employeeMapper;
	@Autowired
	GoodsRepositoryMapper goodsRepositoryMapper;
	
	@Autowired
	Approval_goodsclaimMapper approvalGoodsMapper;
	
	@Override
	public void addGoods_claimGetGc_id(Goods_claim goods_claim) {
		goods_claimMapper.insertGoods_claimGetGc_id(goods_claim);
		
		//插入申领数据成功后，库存要减少:库存数量-申领数量
//		Integer gc_number=goods_claim.getGc_number();
//		String gc_name=goods_claim.getGc_name();
//		if(goods_claim.getGc_status() == 1) {
//			goodsRepositoryMapper.updateGr_numberByGr_name(gc_number,gc_name);
//		}
		
	}

	@Override
	public void modifyGoods_claimByGc_id(Goods_claim goods_claim) {
		goods_claimMapper.updateGoods_claimByGc_id(goods_claim);
		
	}

	@Override
	public void removeGoods_claimByGc_id(Integer gc_id) {
		goods_claimMapper.deleteGoods_claimByGc_id(gc_id);
		//删除对应关系表
		approvalGoodsMapper.deleteApproval_goodsclaim(gc_id);
		
	}

	@Override
	public List<Goods_claim> getGoods_claims() {
		List<Goods_claim> goods_claims = goods_claimMapper.selectGoods_claims();
		return goods_claims;
	}
	
	//根据gc_id查询申领信息和员工信息
	@Override
	public Goods_claim getGoods_claimByGc_id(Integer gc_id) {
		Goods_claim Goods_claim = goods_claimMapper.selectGoods_claimByGc_id(gc_id);
		return Goods_claim;
	}
	
	//查询分页
	@Override
	public PageBean<Goods_claim> getGoods_claimByPage(Integer pageIndex, Integer pageSize, String name) {
		List<Goods_claim> beanList = goods_claimMapper.selectEmployeeIdByName(name, (pageIndex-1)*pageSize, pageSize);
		System.out.println(beanList.get(0).getStay().getS_name());
		Integer totalRecord = goods_claimMapper.selectGoods_claimTotalRecordById(name);
		//System.out.println(totalRecord);
		PageBean<Goods_claim> pb=new PageBean<Goods_claim>();
		pb.setBeanList(beanList);
		pb.setPageIndex(pageIndex);
		pb.setPageSize(pageSize);
		pb.setTotalRecord(totalRecord);
		System.out.println(totalRecord);
		pb.setPageBeginAndPageEnd();
		
		return pb;
	}


}
